package great.project.common.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

/**
 *  oss操作工具
 */
public class OssUtils {

    private OssConfiguration ossConfiguration;

    /**
     *  关闭构造
     */
    private OssUtils (){

    }

    public OssUtilsBuilder builder(Boolean isAutoShutdown){
        return new OssUtilsBuilder(ossConfiguration , isAutoShutdown);
    }

    public OssUtilsBuilder builder(){
        return new OssUtilsBuilder(ossConfiguration , true);
    }


    /**
     *  oss 内部操作类
     */
    public static class OssUtilsBuilder{

        private final OSS oss;

        private final OssConfiguration ossConfiguration;

        private final boolean isAutoShutdown;


        public OssUtilsBuilder(OssConfiguration ossConfiguration , boolean isAutoShutdown) {
            this.ossConfiguration = ossConfiguration;
            this.isAutoShutdown = isAutoShutdown;
            this.oss = new OSSClientBuilder()
                    .build(
                            ossConfiguration.getOssEndPoint(),
                            ossConfiguration.getOssAccessKeyId(),
                            ossConfiguration.getOssAccessKeySecret()
                    );
        }


        /**
         * 关闭OSSClient
         */
        public void shutdown() {
            this.oss.shutdown();
        }


    }

}
